import { getAction } from '@api/manage'
const training = {
  state: {
    trainingId: 1,
    trainingInfo:{}
  },
  mutations: {
    setTrainingId(state,id){
      state.trainingId = id
    },
    clearStateTraining(state){
      state.trainingInfo = {
        courses: [
          {
            courseId: "",
            courseName: ""
          }
        ]
      };
    },
    addCourses(state){
      state.trainingInfo.courses.push(
        {
          courseId: "",
          courseName: ""
        }
      )
    },
    reduceCourses(state,index){
      state.trainingInfo.courses.splice(index,1);
    }

  },
  actions: {
    getTrainingById({state},id){
      getAction('/trainingManage/training/trainingList',  {id} ,'get').then(res =>{
        let data = res.data
        data.users = data.users.map(user => {
          return user.userId
        })
        state.trainingInfo = data
      })
    }
  }
}
export default training